<?php
namespace app\admin\controller;
use app\admin\logic\IntegralLogic;

/**
 * 积分明细api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/11/27
 * Time: 15:48
 */
class Integral extends Base {

    public function __construct(){
        parent::__construct();
        $this->i_logic = new IntegralLogic();
    }

    /**
     * 获取积分明细
     * @return \think\response\Json
     */
    public function ajax_get_integral(){
        $params = input();
        $r = $this->check_admin_token($params);
        if ($r['code'] != 1) {
            return json($r);
        }

        $maps = $this->i_logic->get_search_integral_maps($params['department'],$params['username'],$params['integral_type'],$params['start_time'],$params['end_time']);
        $limit = ($params['page'] -1) * $params['rows'];

        $list = model('integral_record')->get_list($maps,'id,openid,integral,integral_desc,c_time','c_time desc','',$limit,$params['rows']);
        foreach($list as $k => $v){
            //查找用户
            $u_maps = [];
            $u_maps[] = ['openid','=',$v['openid']];
            $u_detail = model('user')->get_detail($u_maps,'id,username,department');
            $list[$k]['username'] = $u_detail['username'];
            $list[$k]['department'] = $u_detail['department'];
        }

        $total_num = model('integral_record')->get_count($maps,'id');

        $data['list'] = $list;
        $data['total_num'] = $total_num;
        return json($this->i_logic->get_response(1,'OK',$data));
    }
}